﻿
Imports System.IO

Public Class Resetoutlookprofile
    Public Shared Sub Resetoutlook(ByVal strcomp As String, ByVal struser As String)
        'Dim Process As Object
        Dim strObject As String
        'Dim strprocuser As String = ""
        Dim resetout As Boolean = True
        strObject = "winmgmts://" & strcomp
        For Each Process In GetObject(strObject).InstancesOf("win32_process")
            'Dim result = Process.getowner(strprocuser)
            If _
                UCase(Process.name) = UCase("outlook.exe") And
                UCase(struser) = UCase(currentusr.CheckCurrentUser(strcomp)) Then
                Dim result2 As DialogResult =
                        MessageBox.Show(
                            "Outlook is currently running for " & struser & " on " & strcomp &
                            " would you like to close it for them?", "", MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question)
                If result2 = DialogResult.Yes Then
                    Process.Terminate()
                    resetout = True
                    Exit For
                ElseIf result2 = DialogResult.No Then
                    resetout = False
                    Exit For
                End If
            End If
        Next
        If resetout Then
            If Directory.Exists("\\" & strcomp & "\c$\users\" & struser & "\appdata\local\microsoft\outlook") Then
                Directory.Delete("\\" & strcomp & "\c$\users\" & struser & "\appdata\local\microsoft\outlook", True)
                MessageBox.Show("Outlook Profile for " & struser & " has been reset")
            Else
                MessageBox.Show(
                    "Outlook profile for " & struser & " has not been reset as profile is in a non standard path")
            End If
        Else
            MessageBox.Show("Outlook profile for " & struser & " has not been reset")
        End If
    End Sub
End Class